package com.cn.mobileproject.view.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.cn.mobileproject.R;
import com.cn.mobileproject.bean.Project;
import com.cn.mobileproject.bean.PubInfo;
import com.cn.mobileproject.data.GlobalValue;

public class PubinfoAdapter extends BaseAdapter{
protected Context mContext;
	
	public PubinfoAdapter(Context context){
		mContext = context;
	}
	
	protected ArrayList<PubInfo> mList ;
	
	@Override
	public int getCount() {
		if(mList==null) return 0;
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		if(mList==null) return null;
		if(position>=mList.size()) return null;
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	class ViewHolder{
		TextView titleText;
		TextView creatorText;
		TextView pubdateText;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.pubinfo_item, null);
			holder = new ViewHolder();
			holder.titleText =(TextView) convertView.findViewById(R.id.pubinfo_item_text_title);
			holder.creatorText =(TextView) convertView.findViewById(R.id.pubinfo_item_text_create);
			holder.pubdateText =(TextView) convertView.findViewById(R.id.pubinfo_item_text_pubdate);
			convertView.setTag(holder);
		}
		else{
			holder = (ViewHolder) convertView.getTag();
		}
		if(position>mList.size()||holder==null) return convertView;
		PubInfo pubinfo = mList.get(position);
		holder.titleText.setText(pubinfo.title);
		holder.creatorText.setText(pubinfo.creator);
		holder.pubdateText.setText(pubinfo.pubDate);
		return convertView;
	}

	public ArrayList<PubInfo> getList() {
		return mList;
	}

	public void setList(ArrayList<PubInfo> list){
		if(mList==null){
			mList = new ArrayList<PubInfo>();
		}
		mList.clear();
		if(list!=null){
			mList.addAll(list);
		}
	}
}
